package pl.edu.pjwstk.kor.database.init;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;

import pl.edu.pjwstk.kor.model.Address;

public class AddressInitalizer extends AbstractDataInitalizer<Address> {

	@Override
	public List<Address> initData() throws Exception {
		List<Address> result = new ArrayList<Address>();
		
		String country = "Polska";
		String city = "Warszawa";
		
		File addressFile = new File("src/main/resources/address.csv");
		List<String> lines = FileUtils.readLines(addressFile, "UTF8");
		
		for(String line : lines) {
			String [] split = line.split(";");
			String postalCode = split[0].trim();
			String street = split[1].trim();
			
			Address address = new Address();
			address.setCity(city);
			address.setCountry(country);
			address.setPostalCode(postalCode);
			address.setStreet(street);
			address.setBuildingNumber(random.nextInt(98) + 1);
			if(random.nextBoolean()) {
				address.setFlatNumber(random.nextInt(20) + 1);
			}
			result.add(address);
		}
		
		return result;
	}

}
